
if (SERVER) then

	local File = {}
	
	function File:FileExists( pc, dir, filename )
		if (!self:ValidPC(pc)) then return false end
		if (!self:DirExists( pc, dir )) then return false end
		return (self:GetStructure(pc)["root" .. dir][filename] != nil)
	end
	
	function File:DirExists( pc, dir )
		if (!self:ValidPC(pc)) then return false end
		return (self:GetStructure(pc)["root" .. dir] != nil)
	end
	
	function File:MakeFolder( pc, dir, folder )
		if (!self:ValidPC(pc)) then return end
		if (self:DirExists( pc, dir )) then return end
		pc:AddDirectory( dir, folder )
	end
	
	function File:DeleteFolder( pc, dir, folder )
		if (!self:ValidPC(pc)) then return end
		if (!self:DirExists( pc, dir )) then return end
		pc.Data[ pc:EntIndex() ].Files[ dir ] = nil
	end
	
	function File:Write( pc, dir, filename, content )
		if (!self:ValidPC(pc)) then return end
		if (!self:DirExists( pc, dir )) then return end
		if (self:FileExists( pc, dir, filename )) then
			// The file already exists, override the contents
			pc.Data[ pc:EntIndex() ].Files[ dir ][ filename ] = content
		else
			// The file doesn't exist, just add it
			pc:AddFile( dir, filename, content )
		end
	end
	
	function File:Read( pc, dir, filename )
		if (!self:ValidPC(pc)) then return end
		if (!self:DirExists( pc, dir )) then return end
		if (!self:FileExists( pc, dir, filename )) then return end
		return (pc.Data[ pc:EntIndex() ].Files[ dir ][ filename ])
	end
	
	function File:ValidPC( pc )
		if (!pc) then return false end
		if (!pc:IsValid()) then return false end
		if (pc:GetClass() != "pcmod_pc") then return false end
		return true
	end
	
	function File:GetStructure( pc )
		if (!self:ValidPC(pc)) then return {} end
		return (pc.Data[pc:EntIndex()].Files)
	end
	
	PCLIB.File = File
	File = nil

end